package com.gitee.cashzhang27.test.cloud.seata.business.service;

import com.gitee.cashzhang27.test.cloud.seata.business.feign.OrderFeignClient;
import com.gitee.cashzhang27.test.cloud.seata.business.feign.StorageFeignClient;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * Description：
 *
 * @author fangliangsheng
 * @date 2019-04-05
 */
@Service
@AllArgsConstructor
public class BusinessService {

  private StorageFeignClient storageFeignClient;
  private OrderFeignClient orderFeignClient;

  /**
   * 减库存，下订单
   */
  @GlobalTransactional
  public void purchase(String userId, String commodityCode, int orderCount) {
    storageFeignClient.deduct(commodityCode, orderCount);

    orderFeignClient.create(userId, commodityCode, orderCount);
  }

}
